package com.study.hot.newActivity

import android.graphics.Bitmap
import android.net.Uri
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.ActivityResultRegistry
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner

/**
 * <pre>
 *     author : slx
 *     time   : 2020/04/13
 *     desc   : 将打开Activity获取结果封装到一个类中，实现与Activity解耦
 * </pre>
 */
class TakePhotoObserver(
        private val registry: ActivityResultRegistry,
        private val listener: (Bitmap) -> Unit
) : DefaultLifecycleObserver {

    private lateinit var takePhotoLauncher: ActivityResultLauncher<Uri?>

    override fun onCreate(owner: LifecycleOwner) {
        super.onCreate(owner)
        //takePhotoLauncher = registry.register("key", ActivityResultContracts.TakePicture()) { bitmap -> listener(bitmap) }
    }

    fun takePhoto() {
        takePhotoLauncher
    }
}